package model;


import enums.BaseRespCodeEnum;
import enums.RespCodeEnum;

/**
 * @author: Anc
 * @date: 2022/7/01
 */
public class ResponseFactory {

    /**
     * 成功响应带返回文案的
     *
     * @param <T>
     * @param msg
     * @param result
     * @return
     */
    public static <T> Response<T> buildSuccessResponse(String msg, T result) {
        return new Response<>(msg, result);
    }

    /**
     * 成功响应带返回文案的
     *
     * @param <T>
     * @return
     */
    public static <T> Response<T> buildSuccessResponse() {
        return new Response();
    }

    /**
     * 成功响应
     *
     * @param result
     * @param <T>
     * @return
     */
    public static <T> Response<T> buildSuccessResponse(T result) {
        return new Response<>(result);
    }

    /**
     * 成功响应
     *
     * @param result
     * @param <T>
     * @return
     */
    public static <T> Response<T> buildSuccessResponse(T result, String sign) {
        Response<T> response = new Response<>(result);
        response.setSign(sign);
        return response;
    }

    /**
     * 失败响应
     *
     * @param <T>
     * @return
     */
    public static <T> Response<T> buildErrorResponse() {
        return new Response<>(BaseRespCodeEnum.SERVER_ERROR.getCode(), BaseRespCodeEnum.SERVER_ERROR.getMsg());
    }

    /**
     * 失败响应
     *
     * @param <T>
     * @return
     */
    public static <T> Response<T> buildErrorResponse(String msg) {
        return new Response<>(BaseRespCodeEnum.SERVER_ERROR.getCode(), msg);
    }

    /**
     * 失败响应
     *
     * @param <T>
     * @return
     */
    public static <T> Response<T> buildParamErrorResponse(String msg) {
        return new Response<>(BaseRespCodeEnum.PARAMS_ILLEGAL.getCode(), msg);
    }

    /**
     * 失败响应
     *
     * @param code
     * @param message
     * @param <T>
     * @return
     */
    public static <T> Response<T> buildErrorResponse(int code, String message) {
        return new Response<>(code, message);
    }
    /**
     * 失败响应
     *
     * @param code
     * @param message
     * @param <T>
     * @return
     */
    public static <T> Response<T> buildErrorResponse(int code, String message,T result) {
        return new Response<>(code, message,result);
    }

    public static <T> Response<T> buildErrorResponse(RespCodeEnum respCodeEnum) {
        return new Response<>(respCodeEnum.getCode(), respCodeEnum.getMsg());
    }

}
